/**
 * @Author: panda
 * @Date: 2022-05-18 10:42
 * @Description: 路由守卫
 */
import {router} from "@/router";
import {useUserStore} from "@/store/modules/user";

router.beforeEach((to, from, next) => {
  if (useUserStore().getUserInfo) {
    next()
  } else {
    const requireAuth = to.matched.some(route => {
      return route.meta.auth
    })
    // 未登录
    if (requireAuth) {
      next({
        name: 'Login',
        query: {
          from: to.fullPath
        }
      })
    }
    if (!requireAuth) {
      next()
    }
  }
})

